package com.iyue.user.helper;

import org.apache.commons.lang.StringUtils;

import com.iyue.Config;
import com.iyue.SpringHelper;
import com.iyue.servlet.taglibs.FunctionsUtil;
import com.iyue.user.pojo.UserBasic;
import com.iyue.user.service.UserBiz;

/**
 * 《用户》实用类
 * 
 * @author fresh
 * @version $Id: UserFunctions.java,v 1.1 2010/10/14 17:07:17 fresh Exp $
 */
public final class UserFunctions extends FunctionsUtil {

	/**
	 * 性别
	 * 
	 * @param sex
	 * @return
	 */
	public static String sex(Integer sex) {
		if (sex == null || "".equals(sex)) {
			return "女";
		}

		String ret = UserBasic.MAP_SEX.get(Integer.valueOf(sex));
		if (ret == null) {
			return "女";
		}

		return ret;
	}

	/**
	 * 
	 * @param url
	 *            头像URL
	 * @return
	 */
	public static String photoUrl(String url) {
		if (StringUtils.isBlank(url)) {
			Config cfg = (Config) SpringHelper.getBean("test");
			return cfg.getImg() + "/images/default.jpg";
		}

		return url;
	}

	/**
	 * 获取用户头像
	 * 
	 * @param username
	 * @return
	 */
	public static String photo(Integer username) {
		UserBiz biz = (UserBiz) SpringHelper.getBean("UserBiz");
		UserBasic basic = biz.basic(username);
		if (basic == null) {
			return photoUrl("");
		}

		return basic.getPhoto();
	}

	/**
	 * 用户基本信息
	 * 
	 * @param username
	 * @return
	 */
	public static UserBasic user(String username) {
		if (username == null) {
			return null;
		}

		UserBiz biz = (UserBiz) SpringHelper.getBean("UserBiz");

		return biz.basic(new Integer(username));
	}
}
